package com.saifan.wyy_ov.ui.album.ui;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.saifan.wyy_ov.R;
import com.saifan.wyy_ov.ui.album.model.ImageGroup;
import com.saifan.wyy_ov.utils.ImgUtil;

import java.util.List;


/**
 * @author WangLi
 * @date 2014年12月4日 下午7:08:56
 * @Description
 * @version V1.0
 */

@SuppressLint("InflateParams")
public class FolderAdapter extends BaseAdapter{
	private List<ImageGroup> list;
	private Activity ac;

	public FolderAdapter(List<ImageGroup> list, Activity ac) {
		super();
		this.list = list;
		this.ac = ac;
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if(convertView == null){
			convertView = ac.getLayoutInflater().inflate(R.layout.album_item, null);
			viewHolder = new ViewHolder();
			viewHolder.folder_img = (ImageView) convertView.findViewById(R.id.covert_img);
			viewHolder.folder_text = (TextView) convertView.findViewById(R.id.album_text);
			convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		ImgUtil.DisPlayImgForLocal(list.get(position).getFirstImgPath(), viewHolder.folder_img, ac);
		viewHolder.folder_text.setText(String.format(ac.getResources().
				getString(R.string.folder_text), list.get(position).getDirName(),list.get(position).getImageCount()));
		return convertView;
	}

	class ViewHolder{
		ImageView folder_img;
		TextView folder_text;
	}
}
